package fr.afcepf.atod12.projet1.dao.implementations;


import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import fr.afcepf.atod12.projet1.dao.interfaces.IDaoTypeMedecin;
import fr.afcepf.atod12.projet1.entities.Medecin;
import fr.afcepf.atod12.projet1.entities.TypeMedecin;

@Service("daoTypeMedecin")
@Transactional 
public class DaoTypeMedecinImpl implements IDaoTypeMedecin {

	@PersistenceContext(unitName="myPersistenceUnit")
	private EntityManager entityManager;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<String> getAllSpecialite() {
		Query query = entityManager.createQuery("select m.specialite from TypeMedecin as m");
		List<String> result = query.getResultList();
		return result;
	}

	
	@SuppressWarnings("unchecked")
	public List<TypeMedecin>getSpecialiteByMedecin(int idMedecin){
		Query query = entityManager.createQuery("select m.typeMedecins from Medecin as m where m.idMedecin=:idMedecin");
		query.setParameter("idMedecin", idMedecin);
		List<TypeMedecin> result = query.getResultList();
		return result;
	}


	@SuppressWarnings("unchecked")
	@Override
	public List<Medecin> getAllMedecinBySpecialite(int idTypeMedecin) {
		Query query = entityManager.createQuery("select tm.medecins from TypeMedecin as tm where tm.idTypeMedecin=:idTypeMedecin");
		query.setParameter("idTypeMedecin", idTypeMedecin);
		List<Medecin> result = query.getResultList();
		return result;
	}
	
}
